import {getLazyTree} from "@/api/base/region";
import {SYSTEM_PREFIX} from "@/store/constant";

export const treeOption = {
  nodeKey: 'id',
  lazy: true,
  treeLoad: function (node, resolve) {
    const parentCode = (node.level === 0) ? "00" : node.data.id;
    getLazyTree(parentCode).then(res => {
      resolve(res.data.data.map(item => {
        return {
          ...item,
          leaf: !item.hasChildren
        }
      }))
    });
  },
  addBtn: false,
  menu: false,
  size: 'small',
  props: {
    labelText: '标题',
    label: 'title',
    value: 'value',
    children: 'children'
  }
}

export const regionOption = {
  labelWidth: 100,
  column: [
    {
      label: "父区划编号",
      prop: "parentCode",
      span: 24,
      disabled: true,
      rules: [{
        required: true,
        message: "请输入父区划编号",
        trigger: "blur"
      }]
    },
    {
      label: "父区划名称",
      prop: "parentName",
      span: 24,
      disabled: true,
    },
    {
      label: "区划编号",
      prop: "code",
      formslot: true,
      span: 24,
      rules: [{
        required: true,
        message: "请输入区划编号",
        trigger: "blur"
      }]
    },
    {
      label: "区划子编号",
      prop: "subCode",
      display: false,
    },
    {
      label: "区划名称",
      prop: "name",
      span: 24,
      rules: [{
        required: true,
        message: "请输入区划名称",
        trigger: "blur"
      }]
    },
    {
      label: "区划等级",
      prop: "level",
      type: "radio",
      dicUrl: SYSTEM_PREFIX + "/dict/dictionary?code=region",
      props: {
        label: "dictValue",
        value: "dictKey"
      },
      dataType: "number",
      span: 24,
      rules: [{
        required: true,
        message: "请选择区划等级",
        trigger: "blur"
      }]
    },
    {
      label: "区划排序",
      prop: "sort",
      type: "number",
      span: 24,
      rules: [{
        required: true,
        message: "请输入区划排序",
        trigger: "blur"
      }]
    },
    {
      label: "区划备注",
      prop: "remark",
      type: "textarea",
      minRows: 6,
      span: 24,
    },
  ]
}

export const debugOption = {
  labelWidth: 50,
  submitBtn: false,
  emptyBtn: false,
  column: [
    {
      label: '省份',
      prop: 'province',
      type: 'select',
      props: {
        label: 'name',
        value: 'code'
      },
      cascaderItem: ['city', 'district'],
      dicUrl: SYSTEM_PREFIX + '/region/select',
      span: 24,
    },
    {
      label: '地市',
      prop: 'city',
      type: 'select',
      props: {
        label: 'name',
        value: 'code'
      },
      dicFlag: false,
      dicUrl: SYSTEM_PREFIX + '/region/select?code={{key}}',
      span: 24,
    },
    {
      label: '区县',
      prop: 'district',
      type: 'select',
      props: {
        label: 'name',
        value: 'code'
      },
      dicFlag: false,
      dicUrl: SYSTEM_PREFIX + '/region/select?code={{key}}',
      span: 24,
    }
  ]
}
